package org.example.pims.security.service;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.springframework.security.core.GrantedAuthority;

/**
 * @author bothin
 */
@JsonIgnoreProperties(ignoreUnknown = true)
public class CustomGrantedAuthority implements GrantedAuthority {
    private static final long serialVersionUID = -636195103741945005L;
    private  String role;

    public CustomGrantedAuthority(String role) {
        this.role = role;
    }

    public CustomGrantedAuthority() {
    }

    @Override
    @JsonIgnore
    public String getAuthority() {
        return this.role;
    }

    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        } else {
            return obj instanceof CustomGrantedAuthority && this.role.equals(((CustomGrantedAuthority) obj).role);
        }
    }

    public int hashCode() {
        return this.role.hashCode();
    }

    public String toString() {
        return this.role;
    }
}
